package net.wexoo.onlinedivelog.view.pages.content.dive;

import java.util.ArrayList;
import java.util.List;

import net.wexoo.onlinedivelog.entity.dive.DiveBean;
import net.wexoo.onlinedivelog.reusable.column.SortPropertyColumn;
import net.wexoo.onlinedivelog.reusable.panel.AjaxLinkPanel;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator;
import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.ISortableDataProvider;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

public class DiveTablePanel extends AbstractTablePanel<DiveBean> {

  private static final long serialVersionUID = 1L;

  public DiveTablePanel(String id, ISortableDataProvider<DiveBean> dataProvider) {
    super(id, dataProvider);
  }

  @Override
  protected List<IColumn<DiveBean>> buildColumns() {
    List<IColumn<DiveBean>> columns = new ArrayList<IColumn<DiveBean>>();

    columns.add(new SortPropertyColumn<DiveBean>(getString("idLabel"), "id"));
    columns.add(new SortPropertyColumn<DiveBean>(getString("dateLabel"), "diveDate"));
    columns.add(new SortPropertyColumn<DiveBean>(getString("diveSiteLabel"), "diveSite"));
    columns.add(new SortPropertyColumn<DiveBean>(getString("depthLabel"), "maxDepth"));
    columns.add(new SortPropertyColumn<DiveBean>(getString("diveGuideLabel"), "diveGuide.login"));
    columns.add(new AbstractColumn<DiveBean>(new Model<String>(getString("detail"))) {

      private static final long serialVersionUID = 1L;

      @Override
      public void populateItem(Item<ICellPopulator<DiveBean>> cellItem, String componentId, final IModel<DiveBean> rowModel) {
        cellItem.add(new AjaxLinkPanel(componentId, getString("openButton")) {

          private static final long serialVersionUID = 1L;

          @Override
          public void clickAction(AjaxRequestTarget target) {

            openDetailView(rowModel.getObject(), target);
          }
        });
      }
    });
    return columns;
  }

  protected void openDetailView(DiveBean bean, AjaxRequestTarget target) {
  }
}